//
//  OrdinaryTeacherAccountVM.m
//  优学荟管理系统
//
//  Created by 星道 on 2017/9/30.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "OrdinaryTeacherAccountVM.h"

@implementation OrdinaryTeacherAccountVM
{
    NSArray <OrdinaryTeacherAccountModel *>*_DataArr;
}

/** 表单的配置 */
- (void)ConfigTableVIew:(UITableView *)TableView {

    TableView.tableFooterView = [UIView new];
    TableView.tableHeaderView = [UIView new];
    TableView.rowHeight = 98*KScale;
    [TableView registerNib:[UINib nibWithNibName:[OrdinaryTeacherAccountCell description] bundle:nil] forCellReuseIdentifier:@"Cell"];
    TableView.delegate = self;
    TableView.dataSource = self;
}

/** 获取老师的信息并通过block回调 */
- (void)RefreshDataWithActivity:(UIActivityIndicatorView *)Activity Complete:(void (^)(NSArray <OrdinaryTeacherAccountModel *>*Arr))Complete {

    NSDictionary *Params = @{
                             @"action"  :@"getTeacherByOid",
                             @"oid"     :[AccountTool shareAccountTool].currentAccount.oid
                             };
    [NetManager Get:LLBaseURL(@"lesson.do") Auth:YES Params:Params Success:^(id Obj) {
        [Activity stopAnimating];
        if ([Obj[@"code"] isEqualToNumber:@1000]) {
            NSMutableArray *Array = [NSMutableArray array];
            [Obj[@"t"] enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [Array addObject:[OrdinaryTeacherAccountModel HNObjectValuesForKey:obj]];
            }];
            dispatch_async(dispatch_get_main_queue(), ^{
                Complete ? Complete ([Array copy]):nil;
            });
        } else {
            [Activity stopAnimating];
            [HUD showError:Obj[@"msg"]];
        }
    } Fail:^(NSError *Error) {
        [HUD showError:NetErr];
    }];
}

/** 是否启用动画去刷新图表 */
- (void)ReloadData:(UITableView *)TableView Arr:(NSArray <OrdinaryTeacherAccountModel *>*)Arr Animate:(BOOL)Animate {
    _DataArr = Arr;
    if (Animate == NO) {
        [TableView reloadData];
    } else {
        [TableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:(UITableViewRowAnimationAutomatic)];
    }
}

/** 表单代理 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _DataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    OrdinaryTeacherAccountCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    Cell.Model = _DataArr[indexPath.row];
    Cell.Upload = self.Upload;
    return Cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [SVProgressHUD showSuccessWithStatus:[_DataArr[indexPath.row] petName]];
}
@end
